package cn.dzh.service_test;

import cn.dzh.model.bean.CommodityBase;
import cn.dzh.model.bean.CommodityDraft;
import cn.dzh.model.dto.HttpResult;
import cn.dzh.service.CommodityDraftService;
import cn.dzh.service.CommodityOperateService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 聂海波
 * @version 1.8
 * @date 2023/10/28 14:32
 */
@SpringBootTest
public class GoodsSelect {
    @Resource
    private CommodityDraftService commodityDraftService;

    @Resource
    private CommodityOperateService commodityOperateService;

    @Test
    public void test1() throws Exception {
        CommodityBase commodityBase=new CommodityBase();
        commodityBase.setGoodsId(1);
        List list = commodityDraftService.selectById(commodityBase.getGoodsId());
        System.out.println(list);
    }
    @Test
    public void test2() throws Exception {
        CommodityBase commodityBase=new CommodityBase();
        List<CommodityBase> list = commodityDraftService.selectBase(commodityBase);
        System.out.println(list);

    }
    @Test
    public void test3() throws Exception{
        CommodityDraft commodityDraft = commodityDraftService.findCommodityDraft(1);
        System.out.println(commodityDraft);
    }
    @Test
    public void test4() throws Exception {
        CommodityDraft  commodityDraft= new CommodityDraft (1, 2, "iPhone X", "aa", "这是一款高端智能手机", "电子产品", "详细描述…", "手机", "Apple", "联系方式…", "全球联保", "不发货地址…", "现金价格", 0.0, 9999.99, 1, 10, 1000, null, null, "上海", "编辑中", "待审核");
        String status = commodityDraftService.selectStatus(1);
        if(status==null){
            System.out.println("不存在");
        }
        if("已下线".equalsIgnoreCase(status)){
            System.out.println("商品已下线，可以编辑");
        }
        int d = commodityDraftService.updateGoodsById(commodityDraft);
        if (d > 0) {
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }
    }
    @Test
    public void test5() throws Exception{
        CommodityBase commodityBase =new CommodityBase();
        Integer pageNum=2 ; Integer pageSize=1;
        pageNum= pageNum == null ? 1 : pageNum;
        pageSize = pageSize == null ? 10 : pageSize;
        PageHelper.startPage(pageNum,pageSize);
        List<CommodityBase> commodityBases = commodityDraftService.selectBase(commodityBase);
        PageInfo<CommodityBase> list = new PageInfo<>(commodityBases);
        System.out.println(list);
        System.out.println(commodityBases);
    }
}
